package com.pic.mgt.monitor.backup;

import java.io.File;
import java.util.Calendar;
import java.util.Date;

import com.pic.mgt.file.io.FileOperation;
import com.pic.mgt.utils.DateConvertUtils;

public abstract class UnitPhysicalBackup implements UnitBackup {
	
	protected String backupUnitPathStr;
	protected String backupUnitBadPathStr;
	protected FileOperation simpleFileOperation;
	
	@Override
	/**
	 * 將路徑字串內的關鍵字部份填入現在日期（年，月，日） 
	 */
	public File getBackupBadUnitPath() {
		return getPathWithNowDate(this.backupUnitBadPathStr);
	}

	@Override
	public File getBackupUnitPath() {
		return getPathWithNowDate(this.backupUnitPathStr);
	}
	
	@Override
	public File getBackupUnitPath(Date specificDate) {
		return getPathWithNowDate(this.backupUnitPathStr, specificDate);
	}
	
	/**
	 *  將路徑字串內的關鍵字部份填入現在的日期（年，月，日）
	 * @param path
	 * @return
	 */
	protected File getPathWithNowDate(String path) {
		String pathWithNowDate = DateConvertUtils.fillDateFieldsInString(path);
		return new File(pathWithNowDate);
	}
	
	/**
	 * 將路徑字串內的關鍵字部份填入指定的日期（年，月，日）
	 * @param path
	 * @param specificDate
	 * @return
	 */
	protected File getPathWithNowDate(String path, Date specificDate) {
		Calendar assignCal = Calendar.getInstance();
		assignCal.setTime(specificDate);
		
		String pathWithSpecificDate = DateConvertUtils.fillDateFieldsInString(path, assignCal);
		return new File(pathWithSpecificDate);
	}
	
	// --- getter and setter ---

	public void setSimpleFileOperation(FileOperation simpleFileOperation) {
		this.simpleFileOperation = simpleFileOperation;
	}
	
	public void setBackupUnitPathStr(String backupUnitPathStr) {
		this.backupUnitPathStr = backupUnitPathStr;
	}

	public void setBackupUnitBadPathStr(String backupUnitBadPathStr) {
		this.backupUnitBadPathStr = backupUnitBadPathStr;
	}

}
